<?php
namespace app\admin\controller;

use app\common\cache\common\IAreaCache;
use app\common\controller\AdminBaseController;
use app\common\enum\HolderType;
use app\common\ext\IDb;
use app\common\ext\IRequest;

class UserHouse extends AdminBaseController{

    /**
     * @功能：用户房产信息
     * @开发者：cxl
     * @return string
     */
    public function user_house_list(){
        //接收参数
        $user_id = IRequest::get('user_id');
        $area = IRequest::get('area');

        //整理区域数据
        $province_id = 0;
        $city_id = 0;
        $area_id = 0;
        if(!empty($area) && is_array($area)){
            if(!empty($area[0])) $province_id = $area[0]; //取得省份
            if(!empty($area[1])) $city_id = $area[1]; //取得城市
            if(!empty($area[2])) $area_id = $area[2]; //取得区域
        }

        //取得属性分类列表
        $area_list = IAreaCache::getAllList(3);

        //设置查询条件
        $where = null;
        if(!empty($user_id)) $where['user_id'] = $user_id;
        if(!empty($province_id)) $where['province_id'] = $province_id;
        if(!empty($city_id)) $where['city_id'] = $city_id;
        if(!empty($area_id)) $where['area_id'] = $area_id;
        $user_house_list = IDb::getInstance('asset_house')->setDbWhere($where)->setDbOrder("user_house_id desc")->pag();

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("area",$area);
        $this->assign("area_list",$area_list);
        $this->assign("user_house_list",$user_house_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：用户房产信息历史
     * @开发者：cxl
     * @return string
     */
    public function user_house_info(){
        //接收参数
        $user_house_id = IRequest::get('user_house_id',IRequest::NOT_EMPTY,"用户房产编号不能为空！");

        //设置查询条件
        $where['user_house_id'] = $user_house_id;
        $user_house_info = IDb::getInstance('asset_house')->setDbWhere($where)->row();

        if($user_house_info['holder_type'] == HolderType::Other){
            $user_house_info['holder'] = $user_house_info['holder_name'];
        }else{
            $user_house_info['holder'] = get_enum_name('holder_type',$user_house_info['holder_type']);
        }

        if($user_house_info['house_type'] != HolderType::Other){
            $user_house_info['house_type_name'] = get_enum_name('house_type',$user_house_info['house_type']);
        }


        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("user_house_info",$user_house_info);

        //渲染模板输出
        return view();
    }
}
